package back.services;

//------------------------------------------------------------//
//JavaGetUrl.java:                                          //
//------------------------------------------------------------//
//A Java program that demonstrates a procedure that can be  //
//used to download the contents of a specified URL.         //
//------------------------------------------------------------//
//Code created by Developer's Daily                         //
//http://www.DevDaily.com                                   //
//------------------------------------------------------------//

import java.io.*;
import java.net.*;

public class GetUrl {
	static String content = null;
	static Integer ckcsum;
	public static boolean execute(String url ) {
		// -----------------------------------------------------//
		// Step 1: Start creating a few objects we'll need.
		// -----------------------------------------------------//

		URL u;
		InputStream is = null;
		DataInputStream dis;
		String s;

		try {
			u = new URL(url);
			is = u.openStream(); // throws an IOException
			dis = new DataInputStream(new BufferedInputStream(is));
			while ((s = dis.readLine()) != null) {
				//System.out.println(s);
				content = s;
				ckcsum = s.hashCode(); 
				System.out.println(ckcsum );
			}
		} catch (MalformedURLException mue) {
			System.out.println("Ouch - a MalformedURLException happened.");
			mue.printStackTrace();
			System.exit(1);
		} catch (IOException ioe) {
			System.out.println("Oops- an IOException happened.");
			ioe.printStackTrace();
			System.exit(1);
		} finally {
			try {
				is.close();
			} catch (IOException ioe) {
				// just going to ignore this one
			}
		} // end of 'finally' clause
		return true;
	} // end of main
}
